package com.gaohe.web.controller.scp;

import java.util.List;

import com.gaohe.scp.domain.vo.CsOrderDetailVo;

import com.gaohe.scp.service.ICsCarService;
import com.gaohe.scp.service.ICsOrderService;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.gaohe.common.annotation.Log;
import com.gaohe.common.core.controller.BaseController;
import com.gaohe.common.core.domain.AjaxResult;
import com.gaohe.common.enums.BusinessType;
import com.gaohe.scp.domain.CsOrderDetail;
import com.gaohe.scp.service.ICsOrderDetailService;
import com.gaohe.common.utils.poi.ExcelUtil;
import com.gaohe.common.core.page.TableDataInfo;

/**
 * 用户订单详情Controller
 *
 * @author liuxiangyu
 * @date 2025-03-27
 */
@RestController
@RequestMapping("/scp/detail")
//@RequestMapping("/scp/orderdetail")
public class CsOrderDetailController extends BaseController
{
    @Autowired
    private ICsOrderDetailService csOrderDetailService;
    @Autowired
    private ICsCarService csCarService;
    @Autowired
    private ICsOrderService csOrderService;

    /**
     * 查询用户订单详情列表
     */
//    @PreAuthorize("@ss.hasPermi('scp:detail:list')")
    @GetMapping("/list")
    public TableDataInfo list(CsOrderDetail csOrderDetail)
    {
        startPage();
        List<CsOrderDetail> list = csOrderDetailService.selectCsOrderDetailList(csOrderDetail);
        return getDataTable(list);
    }

    /**
     * 根据订单id查询订单详细信息   王浩宇
     * */
    @GetMapping("/list1/{orderId}")
    public AjaxResult list1(@PathVariable Long orderId)
    {
        CsOrderDetailVo list = csOrderDetailService.selectCsOrderDetailList1(orderId);
        return AjaxResult.success(list);
    }

    /**
     * 导出用户订单详情列表
     */
//    @PreAuthorize("@ss.hasPermi('scp:detail:export')")
    @Log(title = "用户订单详情", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CsOrderDetail csOrderDetail)
    {
        List<CsOrderDetail> list = csOrderDetailService.selectCsOrderDetailList(csOrderDetail);
        ExcelUtil<CsOrderDetail> util = new ExcelUtil<CsOrderDetail>(CsOrderDetail.class);
        util.exportExcel(response, list, "用户订单详情数据");
    }

    /**
     * 获取用户订单详情详细信息
     */
//    @PreAuthorize("@ss.hasPermi('scp:detail:query')")
//    @GetMapping(value = "/{orderDetailId}")
//    public AjaxResult getInfo(@PathVariable("orderDetailId") Long orderDetailId)
//    {
//        return success(csOrderDetailService.selectCsOrderDetailByOrderDetailId(orderDetailId));
//    }

    /**
     * 新增用户订单详情
     */
//    @PreAuthorize("@ss.hasPermi('scp:detail:add')")
    @Log(title = "用户订单详情", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CsOrderDetail csOrderDetail)
    {
        return toAjax(csOrderDetailService.insertCsOrderDetail(csOrderDetail));
    }

    /**
     * 修改用户订单详情
     */
//    @PreAuthorize("@ss.hasPermi('scp:detail:edit')")
    @Log(title = "用户订单详情", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CsOrderDetail csOrderDetail)
    {
        return toAjax(csOrderDetailService.updateCsOrderDetail(csOrderDetail));
    }

    /**
     * 删除用户订单详情
     */
//    @PreAuthorize("@ss.hasPermi('scp:detail:remove')")
    @Log(title = "用户订单详情", businessType = BusinessType.DELETE)
	@DeleteMapping("/{orderDetailIds}")
    public AjaxResult remove(@PathVariable Long[] orderDetailIds)
    {
        return toAjax(csOrderDetailService.deleteCsOrderDetailByOrderDetailIds(orderDetailIds));
    }
}
